#ifndef _FONT_H_
#define _FONT_H_

///////////////////////////////////
// gw_font.h
// Author: Thomas Fobear
// Last Modified: April 27, 2009
///////////////////////////////////

#include "..\rendering\gw_texturedObject.h"
#include "..\rendering\gw_rendernode.h"
#include "..\rendering\gw_renderer.h"
#include "..\factory\gw_factory.h"
using std::vector;

class RenderNode;

enum FONT_ALIGN { 
	FONT_LEFT = 0, 
	FONT_CENTER, 
	FONT_RIGHT,  
	FONT_TOP,   
	FONT_BOTTOM
};

class Font : public TexturedObject
{
private:
	
	struct StringToDraw
	{
		std::string m_text;
		float m_scale;
		bool m_persistent;
		bool m_isOrtho;
		float m_kerning;

		OrthoRect m_collisionRect;
	};
	
	int		m_texid;				// the id of the font sheet
	int		m_startChar;			// which char in the ascii table the texture starts at
	int		m_numRows, m_numCols;	// num of cells in each row col (cell = width*height rect)
	float	m_width, m_height;		// char dimensions
	float	m_kerning;

	RenderNode m_renderQuad;

	Renderer *m_pRenderer;

	SingleTypeFactory<StringToDraw> m_factory;
	
	Font(const Font &);
	Font &operator=(const Font &);

public:
	Font(void);
	~Font(void);

	void Initialize();
	void Shutdown();

	void AddTextureID(uint _id)				{ m_texid = _id; }
	void SetStartChar(int _start)			{ m_startChar = _start; }
	void SetCharDimensions(float _w, float _h)  { m_width = _w; m_height = _h; }
	void SetFontRowsCols(int _r, int _c)	{ m_numRows = _r; m_numCols = _c; }
	void SetKerning(float _kerning)			{ m_kerning = _kerning; }

	RenderNode &GetRenderQuad(void) { return m_renderQuad; }

	void LoadFont(const char *_szTable, uint _texWidth, uint _texHeight, float _cellsize, float _kerning);

	void RenderStrings(void);
	void RenderLetter(uint _row, uint _col, float _x, float _y, float _scale=1);

	RenderNode& MakeString(const char *_szText, float _x, float _y, // what to write and where is manditory
							Vector4 _color = Vector4(1.0f,1.0f,1.0f,1.0f),
							float _scale=1.0f, bool _persistent = true, float _kerning = -1.0f);

	RenderNode& Make3dString( const char *_szText, Vector3 _pos, Vector4 _color = Vector4(1.0f, 1.0f, 1.0f, 1.0f),
							  float _scale=1.0f, bool persisitent = true);

	static void Render(const RenderNode *_pRN, void *_pVoid);

	//helper(s)
	bool CheckPicking(RenderNode _rn);
};

#endif